Class CheckMethods


  • public class CheckMethods
    extends Object
    The class CheckMethods contains all (static) methods to check the rules from the specifications.

    This class is a static class without a public c'tor.

    Version:
    1.0
    Author:
    Frank Zimmermann (LSV Spitzenverband)
    • Method Detail

      • isEmptyOrNull

        public static boolean isEmptyOrNull​(String testString)
        Checks if testString contains only spaces or is NULL or is an empty string.
         CheckMethods.isEmptyOrNull( null    ) == true 
         CheckMethods.isEmptyOrNull( ""      ) == true 
         CheckMethods.isEmptyOrNull( " "     ) == true
         CheckMethods.isEmptyOrNull( "     " ) == true
         CheckMethods.isEmptyOrNull( " x a " ) == false
         CheckMethods.isEmptyOrNull( "abc "  ) == false
         
        Parameters:
        testString - string that is checked
        Returns:
        true if testString contains only spaces or is NULL or is an empty string and false otherwise.
      • isNumeric

        public static boolean isNumeric​(String testString)
        Checks if testString contains only digits.
         CheckMethods.isNumeric( null    ) == false
         CheckMethods.isNumeric( ""      ) == false
         CheckMethods.isNumeric( "   "   ) == false
         CheckMethods.isNumeric( "12345" ) == true
         CheckMethods.isNumeric( "1x2a5" ) == false
         CheckMethods.isNumeric( "1 234" ) == false
         
        Parameters:
        testString - string that is checked
        Returns:
        true if testString contains only digits, false otherwise.
      • isDate

        public static boolean isDate​(String testDate)
        Checks if testDate is a valid date.

        Parameters:
        testDate - string that is checked (format: jhjjmmtt)
        Returns:
        true if testDate is a valid date, false otherwise.
      • isDate0000

        public static boolean isDate0000​(String testDate)
        Checks if testDate is a valid date and jhjj<2009 or jhjj<2009 and mmtt="0000".

        Parameters:
        testDate - string that is checked (format: jhjjmmtt)
        Returns:
        true if testDate is a valid date and jhjj<2009 or jhjj<2009 and mmtt="0000", false otherwise.
      • isDateNotLaterToday

        public static boolean isDateNotLaterToday​(String testDate)
        Checks if testDate is not later than current date.

        Parameters:
        testDate - string that is checked (format: jhjjmmtt)
        Returns:
        true if testDate is not later than current date.
      • isTime

        public static boolean isTime​(String testTime)
        Checks if testTime is a valid time value.
                 hh >= 00 and hh <= 23
                 mm >= 00 and mm <= 59
                 ss >= 00 and ss <= 59
         

        Parameters:
        testTime - string that is checked (format: hhmmss)
        Returns:
        true if testTime is a valid time value, false otherwise.
      • hasValidEmailCharacters

        public static boolean hasValidEmailCharacters​(String testString)
        Checks if testString contains only valid email characters.

        Parameters:
        testString - string that is checked
        Returns:
        true if testString contains only valid email characters.
      • hasCorrectAtChar

        public static boolean hasCorrectAtChar​(String testString)
        Checks if exactly one @ or § is in testString and whether it is not in first or last position.

        Parameters:
        testString - string that is checked
        Returns:
        true if exactly one @ or § is in testString and is not in first or last position, false otherwise.
      • isCheckDigit

        public static boolean isCheckDigit​(String testString,
                                           int p)
        Checks if the testString is a valid Zahlstellennummer or Betriebsnummer.
        The format of the testString must be 8 digits followed by 7 spaces and hence sums up to a total of 15 characters.

        An obligate parameter specifies the check:

         param=ZAHLSTELLENNUMMER : Checks if the first 3 positions are resp. 106, 107 or 108 and 
                                   if the 8. digit is a valid check digit following spec DEÜV 1.3.2.2 .
         param=BETRIEBSNUMMER    : Checks if the first 3 positions are in the range 001 to 099 or greater 
                                   than 110 and if the 8. digit is a valid check digit following spec 
                                   DEÜV 1.3.2.2 .
         
        The check digit is specified as followed (1.3.2.2 of DEÜV):
        • The digits of Betriebsnummer (pos 1 to 7) beginning from left are multiplied with the factors 1,2,1,2,1,2,1..
        • From each of this product the sum of the digits is calculated.
        • These 7 sums are added.
        • The sum is divided by 10.
        • The remainder is the check digit.
        An alternative check digit is the original check digit plus 5. If this alternative check digit is greater than 9 the last digit is the alternative check digit.
         Example: 87661207    ==>  pos      :   1  2  3  4  5  6  7  8  (pos 8 = check digit)
         ========
                                      Digit :   8  7  6  6  1  2  0  7
                                  factor 1-7:   1  2  1  2  1  2  1
          +--Calculation--------------------------------------------------------+
          !                     weighted sum:   8 14  6 12  1  4  0             !
          !                    sum of digits:   8  5  6  3  1  4  0             !
          !                              sum:   27                              !
          !    remainder from division by 10:   7  <--check digit               !
          !alternative check digit:                                             !
          !                  check digit + 5:   12                              !
          !                       last digit:   2  <--alternative check digit   !
          !                                                                     ! 
          !    result: valid check digit is : 7 or 2                              !                 
          +---------------------------------------------------------------------+
         
        Parameters:
        testString - testString
        p - specifies the test variant
        Returns:
        true if testString is a valid Betriebsnummer or Zahlstellennummer
      • isConstantString

        public static boolean isConstantString​(String testString,
                                               String constant)
        Checks if first argument (testString) is equal to the second argument (the constant) and if testString is not NULL or empty.
        Parameters:
        testString - test string that is compared with constant
        constant - the constant for that the check is performed
        Returns:
        true if testString is equal to the constant, otherwise false
      • isInCharSet

        public static boolean isInCharSet​(char testChar,
                                          String charSet)
        Checks if ch is member of the charSet given as a string charSet

        Parameters:
        testChar - character to be checked
        charSet - character set to be checked against
        Returns:
        true if charSet contains the testChar, false otherwise
      • isDate1LaterDate2

        public static boolean isDate1LaterDate2​(String testDate1,
                                                String testDate2)
        Checks if testDate1 is later than testDate2. If testDate1 or testDate2 is NULL it is replaced with current Date

        Parameters:
        testDate1 - (Format: jhjjmmtt)
        testDate2 - (Format: jhjjmmtt)
        Returns:
        true if testDate1 is later than testDate2, otherwise false
      • isDate1NotLaterDate2PlusXMonths

        public static boolean isDate1NotLaterDate2PlusXMonths​(String testDate1,
                                                              String testDate2,
                                                              int months)
        Checks if testDate1 is not later than end of month from testDate2 plus months. If testDate1 or testDate2 is NULL it is replaced with current Date

        Parameters:
        testDate1 - (Format: jhjjmmtt)
        testDate2 - (Format: jhjjmmtt)
        months - number of months to add to testDate2 before comparing to testDate1
        Returns:
        true if testDate1 is not later than end of month from testDate2 plus months, otherwise false
      • isNDefaultValue

        public static boolean isNDefaultValue​(String testString)
        Checks if testString has only the defaultValue (numeric field: all Zeros)

        Parameters:
        testString - numeric string to be checked
        Returns:
        true if testString has only the defaultValue (numeric field:all Zeros), otherwise false
      • isANDefaultValue

        public static boolean isANDefaultValue​(String testString)
        Checks if testString has only the defaultValue (string field: all spaces)

        Parameters:
        testString - alphanumeric string to be checked
        Returns:
        true if testString has only the defaultValue (string field: all spaces), otherwise false
      • hasForeignLDKZ

        public static boolean hasForeignLDKZ​(String testLDKZ)
        Checks if testLDKZ is a valid LDKZ (see DEÜV Anlage 8)
         CheckMethods.hasForeignLDKZ( ""    ) == false
         CheckMethods.hasForeignLDKZ( "   " ) == false
         CheckMethods.hasForeignLDKZ( "BHT" ) == true 
         CheckMethods.hasForeignLDKZ( "IRL" ) == true 
         CheckMethods.hasForeignLDKZ( "xxx" ) == false 
         CheckMethods.hasForeignLDKZ( " L " ) == false
         

        Parameters:
        testLDKZ - LDKZ that is to be tested (LDKZ is short for: Länderkennzeichen)
        Returns:
        true if testLDKZ is a valid LDKZ, false otherwise

      • hasHomePLZ

        public static boolean hasHomePLZ​(String testPLZ)
        Checks if testPLZ is a valid home PLZ between 01000 ... 99999
         CheckMethods.hasHomePLZ( ""           ) == false
         CheckMethods.hasHomePLZ( "          " ) == false                                       
         CheckMethods.hasHomePLZ( "01000     " ) == true 
         CheckMethods.hasHomePLZ( "44866     " ) == true 
         CheckMethods.hasHomePLZ( "00010     " ) == false 
         CheckMethods.hasHomePLZ( "   44866  " ) == false
         

        Parameters:
        testPLZ - postalcode that is to be tested (PLZ is short for: Postleitzahl/postalcode)
        Returns:
        true if testPLZ is a valid home PLZ, false otherwise

      • hasPLZCharsItl

        public static boolean hasPLZCharsItl​(String testPLZ)
        Checks if testPLZ has valid Itl PLZ chars

        Parameters:
        testPLZ - postalcode that is to be tested (PLZ is short for: Postleitzahl/postalcode)
        Returns:
        true if testPLZ has valid Itl PLZ chars, false otherwise